import cp from 'child_process'
import fs from "fs";
import * as path from "path";

interface Status {
    status: boolean,
    payload: string
}

function start(filename: string): boolean {
    console.log("Info:Start processing " + filename)
    //传入的filename包含拓展名，位于upload文件夹内
    // cp.exec("python xxx.py -input "+filename)
    return true
}

function query(filename: string): Status {
    filename=path.parse(filename).name
    console.log("Info:Querying " + filename)
    if(fs.existsSync("./public/output/"+filename+".png")){
        return {
            status: true,
            payload: "Success"
        }
    }else{
        return {
            status:false,
            payload:"Processing..."
        }
    }
}

export {
    start,
    query
}